<?php

namespace app\controller\web;


use app\service\VersionInfoService;
use app\validate\PageValidate;
use app\validate\VersionInfoValidate;
use share\utils\Helper;

class VersionInfoController extends WebBaseController{

    public function initValidate(){        
        $this->validate = new VersionInfoValidate();
    }

    /**
     * 新增APP版本
     */
    public function add_action(){
        $input = $this->check('addVersion');
        $data = VersionInfoService::addVersion($input);
        return self::ok($data);
    }

    /**
     * 修改APP版本
     */
    public function edit_action(){
        $input = $this->check();
        $data = VersionInfoService::updateVersion($input);
        return self::ok($data);
    }

    /**
     * 删除APP版本
     */
    public function del_action(){
        $input = $this->check();
        $data = VersionInfoService::delVersion($input['id']);
        return self::ok($data);
    }

    /**
     * 列表 搜索
     */
    public function list_action(){
        $page = $this->check('pageInfo',null,(new PageValidate()));
        $input = $this->check();       
        $data = VersionInfoService::getListInfo($input,$page,['id' => 'desc']);
        $data = Helper::arrayListReplaceKey($data,[
            'version_show' => 'versionShow',
            'upgrade_type' => 'upgradeType',
            'app_store' => 'appStore',
        ]);
        $total = VersionInfoService::getListCountInfo($input);
        return self::ok(self::formatPageData($page,$total,$data));
    }

}